package com.da.javatest.leetCode;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author chenlida
 * @date 2019/1/10 11:14
 * @description
 */
public class Code173 {

}

class BSTIterator {
    private List<Integer> result = new ArrayList<>();
    private Iterator<Integer> iterator;

    public BSTIterator(TreeNode root) {
        getList(root);
        iterator = result.iterator();
    }

    /**
     * @return the next smallest number
     */
    public int next() {
        return iterator.next();
    }

    /**
     * @return whether we have a next smallest number
     */
    public boolean hasNext() {
        return iterator.hasNext();
    }

    private void getList(TreeNode node) {
        if (node != null) {
            getList(node.left);
            result.add(node.val);
            getList(node.right);
        }
    }
}
